feat(integrations): Gate user info behind data_collection config#6876
feat(integrations): Gate user info behind data_collection config#6876ericapisani wants to merge 5 commits into
Conversation
The request event processor reads aws_event["identity"] at the top level, but the payloads used by the user info tests nested it under requestContext, so no user was attached and the assertions failed in CI.
Codecov Results 📊✅ 97062 passed | ⏭️ 6410 skipped | Total: 103472 | Pass Rate: 93.81% | Execution Time: 352m 15s 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 76.60%. Project has 2525 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 89.67% 89.66% -0.01%
==========================================
Files 193 193 —
Lines 24321 24425 +104
Branches 8572 8672 +100
==========================================
+ Hits 21809 21900 +91
- Misses 2512 2525 +13
- Partials 1397 1405 +8Generated by Codecov Action |
| if has_data_collection_enabled(client_options): | ||
| if client_options["data_collection"]["user_info"]: | ||
| user_info = sentry_event.setdefault("user", {}) | ||
|
|
||
| identity = aws_event.get("identity") | ||
| if identity is None: | ||
| identity = {} | ||
|
|
||
| id = identity.get("userArn") | ||
| if id is not None: | ||
| user_info.setdefault("id", id) | ||
|
|
||
| ip = identity.get("sourceIp") | ||
| if ip is not None: | ||
| user_info.setdefault("ip_address", ip) | ||
| elif should_send_default_pii(): |
There was a problem hiding this comment.
AWS Lambda body handling skipped when data_collection is enabled
When has_data_collection_enabled is true, the elif should_send_default_pii() branch is skipped, so request body is neither collected nor redacted.
Evidence
has_data_collection_enabledreturns true whendata_collectionis configured in_experiments.- Entering the new
if has_data_collection_enabledbranch at line 441 skips theelif should_send_default_pii()branch at line 456. - Body collection (
request["data"] = aws_event.get("body", "")) and redaction (AnnotatedValue.removed_because_raw_data()) live exclusively inside the skippedelif/elsebranches. data_collection.pyline 178 documents that bodies are collected regardless of PII settings by default.- All new
data_collectiontest payloads use"body": null, so this regression is not exercised.
Identified by Warden · code-review · GGF-TPP
| "identity": { | ||
| "sourceIp": "213.47.147.207", | ||
| "userArn": "42" |
There was a problem hiding this comment.
AWS Lambda user-info tests use non-standard event structure
The test payload changed from standard requestContext.identity to a top-level identity field that doesn't match real AWS API Gateway events, causing tests to verify behavior with a fictional event structure instead of production reality.
Evidence
sentry_sdk/integrations/aws_lambda.py_make_request_event_processorreads user identity viaaws_event.get("identity")directly.- Real AWS API Gateway proxy events nest
identityunderrequestContext(e.g.,test_request_data_with_send_default_pii_falseandtest_request_data_with_data_collection_allowlistin the same file both use"requestContext": {"identity": {...}}). - The changed test and the new
USER_INFO_PAYLOADplaceidentityat the top level, which matches the current code but does not exist in real AWS events, so the assertions pass in tests while the extraction may fail in production.
Identified by Warden · code-review · RCQ-XUC
This is a clean up pass from areas that I missed initially.
Refs PY-2583
Fixes #6746